package com.eenie.common.ui.x5webview;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.eenie.common.R;
import com.eenie.common.base.BaseActivity;
import com.eenie.common.views.AppBar;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebView;

public class BrowserActivity extends BaseActivity {
    AppBar mAppBar;
    X5WebView mWebCommon;
    String mUrl;


    public static void start(Context context, String url) {
        context.startActivity(new Intent(context, BrowserActivity.class).putExtra("url", url));
    }


    @Override
    public int initContentView() {
        return R.layout.activity_browser;
    }


    @Override
    public void initInjector() {
        mUrl = getIntent().getStringExtra("url");
    }

    @Override
    public void initUiAndListener(View view) {

        mAppBar = findViewById(R.id.app_bar);
        mAppBar.bind(this);
        mWebCommon = findViewById(R.id.web_common);
        mWebCommon.loadUrl(mUrl);
        mWebCommon.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                mAppBar.setTitle(title);
            }
        });


    }

    @Override
    public void onBackPressed() {
        if (mWebCommon.canGoBack()) {
            mWebCommon.goBack();
        } else {
            finish();
        }
    }
}
